"""Acoustics with linear advection"""

# PyHCL imports
from hogs.grids import grid1d as grid
import hogs.solvers.linsolver as solvers
import hogs.solvers.flux.acoustics.acoustics_flux as flux
import hogs.solvers.bc.acoustics_bc as bc

import numpy

# create a grid
g = grid.Grid1D(); g.initialize(xlow=-1, xhigh=1, dx=0.001, nb=2, nvar=3)

# create a linear solver
solver = solvers.LinearSolver(nvar = 3, tf = 8.0, grid=g)

# add the flux function
u0 = 0.25; K0 = 0.25; rho0 = 1.0
#solver.flux_function = flux.AcousticswithAdvectionFlux1D(u0, K0, rho0)
solver.flux_function = flux.AcousticswithAdvectionLxfFlux1D(u0, K0, rho0)

# add the boundary conditions
solver.bc = bc.AcousticswithAdvectionBC( velocity = 1 )

# set the grid for the flux function
solver.flux_function.set_grid( solver.grid )

# process command line
solver.setup()

grid = solver.grid; q = grid.q; x = grid.xc

p = q[0]
u = q[1]
phi = q[2]

for i, j in enumerate(x):
    p[i] = 0.5 * numpy.exp(-80 * x[i] * x[i] )
    u[i] = 0.0
    phi[i] = p[i]

    if -0.3 < j < -0.1:
        p[i] += 1.0
        phi[i] = p[i]
    
# solve the system
solver.solve()
